<?php 
	header("Content-Type: text/html; charset=utf-8");
	require_once(dirname(__FILE__) . '/' . 'GuaHaoInfor.class.php');
	require_once(dirname(__FILE__) . '/' . 'push_to_order.php');
	require_once(dirname(__FILE__) . '/' . 'SQLOperation.class.php');
	
	$db = new SQLOperation("localhost", "test");
	if ($db->connect()) {
		if (!empty($_POST['hospital']) && !empty($_POST['hospital_office'])) {
			$account = $_POST['account'];
			$cid = $_POST['cid'];
			$hospital = $_POST['hospital'];
			$hospital_office = $_POST['hospital_office'];
			$office_expert = $_POST['office_expert'];
			$acceptable_price = $_POST['acceptable_price'];
			$order_date = $_POST['order_date'];
			$is_expired = $_POST['is_expired'];
			
			$result = $db->query("server",
					"cid",					
					"hospital='".$hospital."'" ." AND office='".$hospital_office."'");
			if ($result) {
				$guahao_infor = new GuaHaoInfor($hospital, $hospital_office, $office_expert, $order_date);
				$user = new PatientUserInfor($account, "");
				$guahao_infor->setUserInfor($user);
				
				$cid_array = array();
				while (($row = mysql_fetch_array($result)) != NULL) {
					$target = new IGtTarget();
					$target->set_appId(APPID);
					$target->set_clientId($row['cid']);
					$cid_array[] = $target;
				}
				if (sizeof($cid_array) > 0) {
					pushMessageToList2($cid_array, $guahao_infor);
					$arr = array("code"=>0, "msg"=>"request broadcast success");
					echo json_encode($arr);
				} else {
					$arr = array("code"=>1, "msg"=>"no server infor matched");
					echo json_encode($arr);
				}
			} else {
				$arr = array("code"=>100, "msg"=>mysql_error());
				echo json_encode($arr);
			}
		}
	
		$db->close();
	} else {
		$arr = array("code"=>100, "msg"=>mysql_error());
		echo json_encode($arr);
	}
?>